package com.cn.longdistancebusstation.order;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.os.Handler;
import android.os.Message;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.Toast;

import com.alipay.sdk.app.PayTask;
import com.cn.longdistancebusstation.R;
import com.cn.longdistancebusstation.annotation.HolderViewType;
import com.cn.longdistancebusstation.annotation.OrderStatus;
import com.cn.longdistancebusstation.base.BaseActivity;
import com.cn.longdistancebusstation.enumxx.PassengerType;
import com.cn.longdistancebusstation.enumxx.TicketStatus;
import com.cn.longdistancebusstation.global.GlobalVariable;
import com.cn.longdistancebusstation.httpHelper.HttpHelper;
import com.cn.longdistancebusstation.httpapi.HttpService;
import com.cn.longdistancebusstation.model.ListResultII;
import com.cn.longdistancebusstation.model.OrderInfo;
import com.cn.longdistancebusstation.model.OrderResult;
import com.cn.longdistancebusstation.model.PayResult;
import com.cn.longdistancebusstation.model.Result;
import com.cn.longdistancebusstation.model.TicketInfo;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;

public class OrderDetailActivity extends BaseActivity {
    private static final int ALI_PAY_FLAG = 1;
    private static final int REQUEST_CHOOSE_PASSENGER = 1;

    private OrderInfo mOrderInfo;
    private List<TicketInfo> mTicketInfoList;
    private TextView mHintTextView;
    //订单号
    private TextView mOrderNoTextView;
    //订单时间
    private TextView mOrderDateTextView;
    //发车时间
    private TextView mSendDateTextView;
    //出发站
    private TextView mFromStationNameTextView;
    //目的站
    private TextView mToStationNameTextView;
    //车次
    private TextView mBusNoTextView;

    private TextView mPickUpServiceDescTextView;
    //支付按钮
    private Button mPayBtn;
    //取消按钮
    private Button mCancelBtn;
    //退票
    private Button mRefundBtn;
    //最晚支付时间
    private Date mLatestPayDate;
    //订单时间
    private Date mOrderDate;
    //订单状态(已完成、未完成)
    private @OrderStatus int mOrderStatus;
    //
    private Timer mTimer;
    //
    private RecyclerView mRecyclerView;
    private CustomAdapter mCustomAdapter;
    //
    private String mOrderNo;
    private String mSendDate;
    private String pickUp;
    //总价格
    private BigDecimal mTotalAmount;
    //
    private Handler mHandler = new Handler(){
        public void handleMessage(Message message){
            switch (message.what){
                case ALI_PAY_FLAG:
                {
                    PayResult payResult = new PayResult((Map<String, String>) message.obj);
                    /**
                     对于支付结果，请商户依赖服务端的异步通知结果。同步通知结果，仅作为支付结束的通知。
                     */
                    String resultInfo = payResult.getResult();// 同步返回需要验证的信息
                    String resultStatus = payResult.getResultStatus();
                    // 判断resultStatus 为9000则代表支付成功
                    if (TextUtils.equals(resultStatus, "9000")) {
                        // 该笔订单是否真实支付成功，需要依赖服务端的异步通知。
                        Toast.makeText(OrderDetailActivity.this, "支付成功", Toast.LENGTH_SHORT).show();
                        finish();
                    } else {
                        // 该笔订单真实的支付结果，需要依赖服务端的异步通知。
                        Toast.makeText(OrderDetailActivity.this, "支付失败", Toast.LENGTH_SHORT).show();
                    }
                }
                break;
            }
        }
    };
    //
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_order_detail);
        this.getTitleTextView().setText("详情");
        //
        Intent intent = getIntent();
        mOrderNo = intent.getStringExtra("orderNo");
        mSendDate = intent.getStringExtra("sendDate");
        mOrderStatus = intent.getIntExtra("orderStatus", 0);
        pickUp=intent.getStringExtra("pickUp");
        //
        mTotalAmount = new BigDecimal(0);
        mTimer = new Timer();
        mTicketInfoList = new ArrayList<>();
        mOrderNoTextView = (TextView)findViewById(R.id.textView_orderNo);
        mOrderDateTextView = (TextView)findViewById(R.id.textView_orderDate);
        mSendDateTextView = (TextView)findViewById(R.id.textView_sendDate);
        mBusNoTextView = (TextView)findViewById(R.id.textView_busNo);
        mPickUpServiceDescTextView =(TextView)findViewById(R.id.textView_pickUpService_desc);
        mHintTextView = (TextView)findViewById(R.id.textView_payHint);
        mFromStationNameTextView = (TextView)findViewById(R.id.textView_fromStationName);
        mToStationNameTextView = (TextView)findViewById(R.id.textView_toStationName);
        mPayBtn = (Button)findViewById(R.id.btn_pay);
        mPayBtn.setVisibility(View.GONE);
        mCancelBtn = (Button)findViewById(R.id.btn_cancel);
        mCancelBtn.setVisibility(View.GONE);
        mRefundBtn = (Button)findViewById(R.id.btn_refund);
        mRefundBtn.setVisibility(View.GONE);
        if("已取票".equals(pickUp)){
            mRefundBtn.setVisibility(View.GONE);
        }
        //
        mRecyclerView = (RecyclerView)findViewById(R.id.recyclerView);
        mCustomAdapter = new CustomAdapter();
        mRecyclerView.setAdapter(mCustomAdapter);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
        //
        getOrderDetail();
        registerBroadcast();

    }

    /*
    * 显示订单信息
    * */
    private void prepareForLayout(){
        //已完成的订单不需要显示支付倒计时提示
        if(mOrderStatus == OrderStatus.ORDER_FINISH){
            mHintTextView.setVisibility(View.GONE);
            mPayBtn.setVisibility(View.GONE);
            mCancelBtn.setVisibility(View.GONE);
        }
        else{
            mHintTextView.setVisibility(View.VISIBLE);
            mRefundBtn.setVisibility(View.GONE);
            mPayBtn.setVisibility(View.VISIBLE);
            mCancelBtn.setVisibility(View.VISIBLE);
        }
        //判断是否需要显示退票按钮
        Boolean isShow = false;
        for (int i = 0; i < mTicketInfoList.size(); i++) {
            TicketInfo ticketInfo = mTicketInfoList.get(i);
            if (!isShow && ticketInfo.getTicket_status() == TicketStatus.TICKET_PAY.code) {
                isShow = true;
            }
            //获取总价格
            if ("0".equals(ticketInfo.getIsToGate())) {
                mTotalAmount = mTotalAmount.add(new BigDecimal(ticketInfo.getTicketPrice())).add(new BigDecimal(ticketInfo.getInsurancePrice()))
                        .add(new BigDecimal(ticketInfo.getToGateFee()));
            }else{
                mTotalAmount = mTotalAmount.add(new BigDecimal(ticketInfo.getTicketPrice())).add(new BigDecimal(ticketInfo.getInsurancePrice()));
            }
        }

        if(isShow) mRefundBtn.setVisibility(View.VISIBLE);
        //
        TicketInfo ticketInfo = mTicketInfoList.get(0);
        if(ticketInfo.getIsFromGate().equals("0")){
            //选择了接站服务
            mPickUpServiceDescTextView.setVisibility(View.VISIBLE);
        }
        mOrderNoTextView.setText("订单号:" + ticketInfo.getOrderNo());
        mOrderDateTextView.setText("订单日期:" + ticketInfo.getOrderDate());
        if(ticketInfo.getIsFlow() == 1){
            mSendDateTextView.setText("发车时间:" + ticketInfo.getSendTime().split(" ")[0] + " 流水车");
        }
        else{
            mSendDateTextView.setText("发车时间:" + ticketInfo.getSendTime());
        }

        mBusNoTextView.setText(ticketInfo.getBusNo());
        mFromStationNameTextView.setText("济南");
        mToStationNameTextView.setText(ticketInfo.getToStationName());
        //
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try
        {
            mLatestPayDate = dateFormat.parse(ticketInfo.getLatestPayDate());
            final Date curDate = new Date();
            long diff = mLatestPayDate.getTime() - curDate.getTime();
            TimerTask timerTask = new TimerTask() {
                @Override
                public void run() {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            long diff = mLatestPayDate.getTime() - new Date().getTime();
                            if(diff<0){
                                mTimer.cancel();
                                mHintTextView.setVisibility(View.GONE);
                                Toast.makeText(OrderDetailActivity.this, "订单已取消", Toast.LENGTH_SHORT).show();
                                finish();
                            }
                            else{
                                long minute = diff/(1000*60);
                                long second = (diff - minute*60*1000)/1000;
                                String strHint = "请在"+minute+"分"+second+"秒内完成支付，否则订单会被取消";
                                mHintTextView.setText(strHint);
                            }
                        }
                    });
                }
            };
            if(diff > 0){
                mTimer.schedule(timerTask, 1000, 1000);
            }
        }
        catch(ParseException e)
        {}
    }

    private void getOrderDetail(){
        showHud();
        Retrofit retrofit = new HttpHelper.HttpServiceBuilder().build().getRetrofit();
        HttpService httpService = retrofit.create(HttpService.class);
        Call<ListResultII<TicketInfo>> call = httpService.getOrderDetail(mOrderNo, mSendDate);
        call.enqueue(new Callback<ListResultII<TicketInfo>>() {
            @Override
            public void onResponse(Call<ListResultII<TicketInfo>> call, Response<ListResultII<TicketInfo>> response) {
                hideHud();
                ListResultII listResult = response.body();
                Log.d("订单详情",listResult+"");
                if(listResult.getHead().getSuccess()){
                    mTicketInfoList = listResult.getData();
                    prepareForLayout();
                    mCustomAdapter.notifyDataSetChanged();
                }
                else {
                    //请求失败
                    Toast.makeText(OrderDetailActivity.this, listResult.getHead().getMsg(), Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onFailure(Call<ListResultII<TicketInfo>> call, Throwable t) {
                hideHud();
                Toast.makeText(getApplicationContext(), t.getLocalizedMessage(), Toast.LENGTH_SHORT);
            }
        });
    }
    /*
    * 支付订单
    * */
    public void toPay(View view){
//        showHud();
//        Retrofit retrofit = new HttpHelper.HttpServiceBuilder().build().getRetrofit();
//        HttpService httpService = retrofit.create(HttpService.class);
//        Call<Result<String>> call = httpService.getEncryptOrderInfo(mOrderNo, "0.01", mSendDate, GlobalVariable.getUserID());
//        call.enqueue(new Callback<Result<String>>() {
//            @Override
//            public void onResponse(Call<Result<String>> call, Response<Result<String>> response) {
//                hideHud();
//                Result result = response.body();
//                if(result.getHead().getSuccess()){
//                    //然后判断body里的flags是否都为true
//                    String strEncryptOrderInfo = result.getBody().toString();
//                    //
//                    aliPay(strEncryptOrderInfo);
//                }
//                else{
//                    Toast.makeText(getApplicationContext(), "支付失败", Toast.LENGTH_SHORT).show();
//                }
//            }
//
//            @Override
//            public void onFailure(Call<Result<String>> call, Throwable t) {
//                hideHud();
//                Toast.makeText(getApplicationContext(), t.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
//            }
//        });
        Intent in=new Intent(OrderDetailActivity.this,PaymentActivity.class);
        in.putExtra("orderNo",mOrderNo);
        in.putExtra("sendDate",mSendDate);
        in.putExtra("totalAmount",mTotalAmount.toString());
        startActivity(in);
    }
    /*
    * 阿里支付
    * */
    private void aliPay(final String orderInfo){
        Runnable payRunnable = new Runnable() {

            @Override
            public void run() {
                PayTask alipay = new PayTask(OrderDetailActivity.this);
                Map<String, String> result = alipay.payV2(orderInfo, true);
                Log.i("msp", result.toString());

                Message msg = new Message();
                msg.what = ALI_PAY_FLAG;
                msg.obj = result;
                mHandler.sendMessage(msg);
            }
        };

        Thread payThread = new Thread(payRunnable);
        payThread.start();
    }
    /*
    * 取消订单
    * */
    public void toCancel(View view){
        showHud();
        StringBuilder strSeats = new StringBuilder("");
        for(int i=0; i<mTicketInfoList.size(); i++){
            TicketInfo ticketInfo = mTicketInfoList.get(i);
            if(strSeats.length() == 0){
                strSeats.append(ticketInfo.getSeatNo());
            }
            else{
                strSeats.append(","+ticketInfo.getSeatNo());
            }
        }
        Retrofit retrofit = new HttpHelper.HttpServiceBuilder().build().getRetrofit();
        HttpService httpService = retrofit.create(HttpService.class);
        Call<OrderResult> call = httpService.cancelOrder(mOrderNo, mSendDate, strSeats.toString());
        call.enqueue(new Callback<OrderResult>() {
            @Override
            public void onResponse(Call<OrderResult> call, Response<OrderResult> response) {
                hideHud();
                OrderResult orderResult = response.body();
                if(orderResult.getHead().getSuccess()){
                    //然后判断body里的flags是否都为true
                    List<String> flagList = orderResult.getBody().getFlags();
                    if(flagList.contains("false")){
                        Toast.makeText(getApplicationContext(), "取消订单失败", Toast.LENGTH_SHORT).show();
                    }
                    else{
                        Toast.makeText(getApplicationContext(), "取消订单成功", Toast.LENGTH_SHORT).show();
                        finish();
                    }
                }
                else{
                    Toast.makeText(getApplicationContext(), "取消订单失败", Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onFailure(Call<OrderResult> call, Throwable t) {
                hideHud();
                Toast.makeText(getApplicationContext(), t.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
            }
        });
    }
    /*
    * 退票
    * */
    public void toRefund(View view){
        Date nowDate=new Date();
        String mDate=mSendDate;
        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date date=dateFormat.parse(mDate);
            boolean flag=date.after(nowDate);
            if(flag){
                final StringBuilder strSeats = new StringBuilder("");
                BigDecimal refundTotalPrice = new BigDecimal("0");
                for(int i=0; i<mTicketInfoList.size(); i++){
                    TicketInfo ticketInfo = mTicketInfoList.get(i);
                    if(ticketInfo.getChoose()){
                        if(strSeats.length() == 0){
                            strSeats.append(ticketInfo.getSeatNo());
                        }
                        else{
                            strSeats.append(","+ticketInfo.getSeatNo());
                        }
                        refundTotalPrice = refundTotalPrice.add(new BigDecimal(ticketInfo.getRefundPrice()));
                    }
                }
                if(strSeats.length() == 0){
                    Toast.makeText(OrderDetailActivity.this, "请先选中车票", Toast.LENGTH_SHORT).show();
                    return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(OrderDetailActivity.this);
                builder.setTitle("温馨提示:");
                builder.setMessage("确定要退票？退票手续费为：" + refundTotalPrice.setScale(2).toString() + "元");
                builder.setPositiveButton("确定",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                showHud();
                                Retrofit retrofit = new HttpHelper.HttpServiceBuilder().build().getRetrofit();
                                HttpService httpService = retrofit.create(HttpService.class);
                                Call<Result> call = httpService.refundTicket(mOrderNo, strSeats.toString(), mSendDate,GlobalVariable.getUserID());
                                call.enqueue(new Callback<Result>() {
                                    @Override
                                    public void onResponse(Call<Result> call, Response<Result> response) {
                                        hideHud();
                                        Result result = response.body();
                                        if(result.getHead().getSuccess()){
                                            Toast.makeText(OrderDetailActivity.this, "退票成功", Toast.LENGTH_SHORT).show();
//                                    getIntegration();
                                            finish();
                                        }
                                        else{
                                            Toast.makeText(getApplicationContext(), result.getHead().getMsg(), Toast.LENGTH_SHORT).show();
                                        }
                                    }

                                    @Override
                                    public void onFailure(Call<Result> call, Throwable t) {
                                        hideHud();
                                        Toast.makeText(getApplicationContext(), t.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
                                    }
                                });
                                mCustomAdapter.notifyDataSetChanged();
                            }
                        });
                builder.setNegativeButton("取消",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        });
                builder.show();

            }else{
                Toast.makeText(OrderDetailActivity.this,"已超过发车时间，如需退票，请到汽车站办理",Toast.LENGTH_SHORT).show();
                return;

            }
        } catch (ParseException e) {
            e.printStackTrace();
        }

    }

//    private void getIntegration() {
//        Retrofit retrofit=new HttpHelper.HttpServiceBuilder().build().getRetrofit();
//        HttpService httpService=retrofit.create(HttpService.class);
//        Call<Result<Integration>> call=httpService.getIntegration(GlobalVariable.getUserID());
//        showHud();
//        call.enqueue(new Callback<Result<Integration>>() {
//            @Override
//            public void onResponse(Call<Result<Integration>> call, Response<Result<Integration>> response) {
//                hideHud();
//                Gson gson = new Gson();
//                Result result = response.body();
//                Boolean isSuccess = result.getHead().getSuccess();
//                Integration integration=(Integration) result.getBody();
//                if(isSuccess){
//                    String integrations=integration.getIntegral();
//                    SharedPreferences.Editor editor=getSharedPreferences("data",MODE_PRIVATE).edit();
//                    editor.putString("integration",integrations);
//                    editor.commit();
//
//                }
//
//            }
//
//            @Override
//            public void onFailure(Call<Result<Integration>> call, Throwable t) {
//                hideHud();
//
//            }
//        });
//    }

    MyReceiver receiver;
    private void registerBroadcast() {
        // 注册广播接收者
        receiver = new MyReceiver();
        IntentFilter filter = new IntentFilter();
        filter.addAction("close_current_boundary");
        this.registerReceiver(receiver,filter);
    }
    class MyReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            if(intent.getAction().equals("close_current_boundary")){
                finish();
            }
        }
    }
    private class CustomViewHolder extends RecyclerView.ViewHolder{
        private TextView mNameTextView;
        private TextView mCardNoTextView;
        private TextView mTypeTextView;
        private TextView mPriceTextView;
        private TextView mStatusTextView;
        private CheckBox mCheckBox;
        private TicketInfo mTicketInfo;
        private TextView mTotalAmountTextView;
        private TextView mSendFeeTextView;
        public CustomViewHolder(View itemView, @HolderViewType int type){
            super(itemView);
            if(type == HolderViewType.HOLDER_VIEW_TYPE_ITEM){
                mNameTextView = itemView.findViewById(R.id.confirmOrder_list_item_name_textView);
                mCardNoTextView = itemView.findViewById(R.id.confirmOrder_list_item_cardNo_textView);
                mTypeTextView = itemView.findViewById(R.id.textView_type);
                mPriceTextView = itemView.findViewById(R.id.textView_price);
                mStatusTextView = itemView.findViewById(R.id.textView_status);
                mCheckBox = itemView.findViewById(R.id.checkBox);
                mCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                        mTicketInfo.setChoose(b);
                        if(b==true){
                            mRefundBtn.setBackgroundColor(Color.parseColor("#3e83f8"));
                        }else{
                            mRefundBtn.setBackgroundColor(Color.parseColor("#cccccc"));

                        }
                    }
                });
            }
            else{
                mTotalAmountTextView = (TextView)itemView;
                mTotalAmountTextView.setTextColor(Color.BLACK);
                mTotalAmountTextView.setTextSize(25);
            }
        }
        public void bindData(String content){
            mTotalAmountTextView.setText(content);
        }
        public void bindData(TicketInfo ticketInfo){
            mTicketInfo = ticketInfo;
            mNameTextView.setText(ticketInfo.getPassengerName());
            mCardNoTextView.setText(ticketInfo.getPassengerCardNo());
            //乘客类型
            int flag = ticketInfo.getPassenger_type();
            PassengerType passengerType = PassengerType.getPassengerType(flag);
            mTypeTextView.setText(passengerType.desc);
            //价格
            String strTicketPrice = "车票:"+ticketInfo.getTicketPrice()+"元";
//            String disCount = "折扣:"+ticketInfo.getDiscountRate()+"折";
            int discountNum=100;
            int percent=10;
            int discountRate= discountNum-Integer.parseInt(ticketInfo.getDiscountRate());
            BigDecimal a;
            BigDecimal b;
            BigDecimal bigDecimal;
            a = new BigDecimal(percent);
            b = new BigDecimal(discountRate);
            bigDecimal=b.divide(a, 1, RoundingMode.HALF_UP);
            //如果有选择送站服务，则显示送站费用描述
            String strSendServiceFeeDesc = "";
            if("0".equals(mTicketInfo.getIsToGate())){
                strSendServiceFeeDesc = "  送站费用:"+ticketInfo.getToGateFee() + "元";
            }
            //
            if("0".equals(ticketInfo.getDiscountRate())){
                mPriceTextView.setText(strTicketPrice + strSendServiceFeeDesc);
            }else{
                mPriceTextView.setText(strTicketPrice + " " + "("+bigDecimal+"折"+")" + strSendServiceFeeDesc);
            }
            //状态
            int statusFlag = ticketInfo.getTicket_status();
            TicketStatus ticketStatus = TicketStatus.getTicketStatus(statusFlag);
            mStatusTextView.setText(ticketStatus.desc);
            //是否选中的状态
            mCheckBox.setChecked(ticketInfo.getChoose()==null ? false : ticketInfo.getChoose());
            //设置复选框是否可见
            if(mOrderStatus == OrderStatus.ORDER_FINISH){
                if(statusFlag == TicketStatus.TICKET_PAY.code){
                    mCheckBox.setVisibility(View.VISIBLE);

                }
                else{
                    mCheckBox.setVisibility(View.INVISIBLE);
                }
            }
            else{
                //未完成的订单,则复选框不可见
                mCheckBox.setVisibility(View.INVISIBLE);
            }
        }
    }

    private class CustomAdapter extends RecyclerView.Adapter<CustomViewHolder>{
        @Override
        public CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            LayoutInflater layoutInflater = LayoutInflater.from(getApplicationContext());
            View view = null;
            if(viewType == HolderViewType.HOLDER_VIEW_TYPE_ITEM){
                view = layoutInflater.inflate(R.layout.order_detail_ticket_info, parent, false);

            }
            else{
                view = layoutInflater.inflate(android.R.layout.simple_list_item_1, parent, false);
            }
            CustomViewHolder customViewHolder = new CustomViewHolder(view, viewType);
            return customViewHolder;
        }

        @Override
        public void onBindViewHolder(CustomViewHolder holder, int position) {
            if(position == mTicketInfoList.size()){
                holder.bindData("总计:" + mTotalAmount.setScale(2).toString() + "元");
            }
            else{
                TicketInfo ticketInfo = mTicketInfoList.get(position);
                holder.bindData(ticketInfo);
            }
        }

        @Override
        public int getItemCount() {
            if(mTicketInfoList.size()>0)
            {
                //显示footerView
                return mTicketInfoList.size()+1;
            }
            return mTicketInfoList.size();
        }

        @Override
        public int getItemViewType(int position) {
            if(position == mTicketInfoList.size()){
                return HolderViewType.HOLDER_VIEW_TYPE_FOOTER;
            }
            else{
                return HolderViewType.HOLDER_VIEW_TYPE_ITEM;
            }
        }
    }
}
